package kr.ragne.framework;

import android.graphics.Canvas;
import android.view.SurfaceHolder;

public class GameViewThread extends Thread {
	//접근을 위한 멤버 변수
	private SurfaceHolder mSurfaceHolder;
	private GameView mGameView;
	// 스레드 실행 상태 멤버 변수
	private boolean mRun = false;
	
	public GameViewThread(SurfaceHolder surfaceHolder, GameView gameview) {
		mSurfaceHolder = surfaceHolder;
		mGameView = gameview;
	}
	
	public void setRunning(boolean run){
		mRun = run;
	}
	
	public void run() {
		Canvas canvas;
		while(mRun){
			canvas = null;
			try{
				mGameView.Update();
				// SurfaceHolder를 통해 Surface에 접근해서 가져옴
				canvas = mSurfaceHolder.lockCanvas(null);
				synchronized (mSurfaceHolder) {
					mGameView.draw(canvas);	//그림을 그림
				}
			}finally{
				if(canvas!=null)
					//Surface를 화면에 표시함
					mSurfaceHolder.unlockCanvasAndPost(canvas);
			}
		}
	}
	
}
